package com.honeycomb.db.dao.hibernate.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.honeycomb.db.dao.BaseHibernateDao;
import com.honeycomb.db.dao.hibernate.IUserPasswordDao;
import com.honeycomb.db.entity.UserPassword;

public class UserPasswordDaoImpl extends BaseHibernateDao<UserPassword,String> implements IUserPasswordDao {
	
	/**
	 * @author ZhongJiang
	 * @create 2012-10-23
	 * @function 查询用户密码（用于用户登录查询）
	 * @param userEmail 用户ID
	 * @param userPassword 用户密码
	 * @return List
	 */
	@Override
	public List<UserPassword> findUserPasswordInfo(final String userEmail,final String userPassword) {
		List<UserPassword> resultList = null;
		try {
			List userPasswordList = this.getHibernateTemplate().executeFind(new HibernateCallback() {
				@Override
				public Object doInHibernate(Session session)
						throws HibernateException, SQLException {
					Query query = session.createQuery("from UserPassword up where up.userId =:ui and up.passwordValue =:pv");
					query.setString("ui", userEmail);
					query.setString("pv", userPassword);
					return query.list();
				}
			});
			resultList = userPasswordList;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultList;
	}
	
}
